﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <div id="content">
        <h1>Let's find the maximal increasing sequence in an array.<br />
            Please input the array elements separated by a single white space :)</h1>
        <div id="input">
            <label for="input-arr">Your array:</label>
            <input type="text" id="input-arr" />
        </div>
        <div id="button">
            <a href="#" onclick="checkButton()">Check</a>
        </div>
    </div>
    
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>

    <script>
        function checkButton() {
            var input = document.getElementById("input-arr").value;
            var myArray = input.split(" ");
			
			var answer=0;
            var numIndex = 0;
            var currentLength = 1;
            var bestLength = 1;

            for (var i = 1; i < myArray.length; i++) {
                currentLength = myArray[i - 1] < myArray[i] ? currentLength + 1 : 1;

                if (currentLength > bestLength) {
                    bestLength = currentLength;
                    numIndex = i - currentLength + 1;
                }
            }

            for (var i = 0; i < bestLength; i++) {
				answer+=myArray[numIndex+i];
 
            }
			               jsConsole.write(answer);
        }
    </script>
</body>
</html>